package cn.secby.wms.util;

import lombok.Data;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
public class TabuMapTree {

    Map<String,TabuMapTree> sonTreeMap = new HashMap<>();

    Square nodeSquare;

    public void add(List<Square> squareList, int index){
        if(index>=squareList.size()){
            return;
        }
        if(nodeSquare == null){
            nodeSquare = squareList.get(index);
            index++;
        }
        Square square = squareList.get(index);
        String id = square.getId();
        if(sonTreeMap.containsKey(id)){
            sonTreeMap.get(id).add(squareList,index+1);
        }else{
            TabuMapTree tabuMapTree = new TabuMapTree();
            tabuMapTree.setNodeSquare(square);
            sonTreeMap.put(id,tabuMapTree);
            sonTreeMap.get(id).add(squareList,index+1);
        }
    }

    public boolean contains(List<Square> squareList,int index){
        if(index>=squareList.size()){
            return true;
        }
        Square square = squareList.get(index);
        String id = square.getId();
        if(sonTreeMap.containsKey(id)){
            return sonTreeMap.get(id).contains(squareList,index+1);
        }else{
            return false;
        }
    }

    public void show(){
        for (String key : sonTreeMap.keySet()) {
            String id = sonTreeMap.get(key).getNodeSquare().getId();
            sonTreeMap.get(key).show();
        }
    }

    // 判断两个Squre是否相等
    public boolean isEq(Square square1, Square square2){
        return square1.getId().equals(square2.getId());
    }

}